from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base():
    def __init__(self):
        cap = {
            "platformName": "Android",#测试平台
            "appium:deviceName": "emulator-5554",#模拟器
            "appium:automationName": "uiautomator2",#驱动
            "appium:appPackage": "com.achievo.vipshop",#测试应用
            "appium:appActivity": ".homepage.activity.MainActivity",#应用活动
            "appium:noReset": True #重置
        }
        # 创建链接
        self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        # 隐时等待
        self.driver.implicitly_wait(20)
    # 找元素
    def find_ele(self,loc):
        ele = self.driver.find_element(*loc)
        return ele
    # 显示等待
    def find_ele_webD(self,loc):
        ele = WebDriverWait(self.driver,20).until(EC.element_to_be_clickable(loc))
        return ele
    # 截图
    def find_save_screenshot(self,a):
        self.driver.save_screenshot(a)
    # 轻敲
    def find_tap(self,x,y):
        self.driver.tap([(x,y),],300)
    # 滑动
    def find_swipe(self,a,b,c,d):
        self.driver.swipe(a,b,c,d,300)
    # 退出
    def find_quit(self):
        self.driver.quit()
    # 关闭
    def find_close(self):
        self.driver.close()

